﻿using ERPEF;
using ERPEF.Model;
using ERPIService;
using Microsoft.EntityFrameworkCore;

using S4Project;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERPService
{
    public class bs_modelService : bs_modellService
    {
        private readonly MyDbContext myDbContext;
        public bs_modelService(MyDbContext myDbContext)
        {
            this.myDbContext = myDbContext;
        }
        //查询

        public async Task<List<bs_model>> Query()
        {
            return await myDbContext.bs_Model.Where(c => c.IsDeleted == false).ToListAsync();
        }

        //添加
        public async Task<int> Add(bs_model bs_Model)
        {
            myDbContext.bs_Model.Add(bs_Model);
            return await myDbContext.SaveChangesAsync();
        }

        //逻辑删除
        public async Task<int> Delete(int model_id)
        {
            var del = myDbContext.bs_Model.Find(model_id);
            if (del != null)
            {
                del.IsDeleted = true;
                await myDbContext.SaveChangesAsync();
                return 1;
            }
            return 0;
        }

        //查询单个字典
        public async Task<List<bs_dict_data>> DictQuery()
         {
            return await myDbContext.bs_dict_data.Where(c => c.IsDeleted == false).ToListAsync();
         }

        //查询产品名称
        public async Task<List<bs_dict_image>> InmgerQuery()
        {
            return await myDbContext.bs_dict_image.Where(c => c.IsDeleted == false).ToListAsync();
        }

        //修改
        public async Task<int> Update(bs_model bs_Model)
        {
            myDbContext.bs_Model.Update(bs_Model);
            return await myDbContext.SaveChangesAsync();
        }
    }
}
